package ar.fiuba.tp7552.buildadmin.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.springframework.transaction.annotation.Transactional;

import ar.fiuba.tp7552.buildadmin.dao.GenericDaoHibernate;
import ar.fiuba.tp7552.buildadmin.dao.UserDao;
import ar.fiuba.tp7552.buildadmin.model.auth.User;

@Transactional
public class UserDaoImpl extends GenericDaoHibernate<User, Long> implements UserDao{

	public UserDaoImpl() {
		super(User.class);
	}
	
	@Override
	public User findByUsername(String username) {
		Session session = this.getHibernateSession();
		Criteria criteria = session.createCriteria(User.class);
		criteria.add(Expression.eq("username", username))
			.setMaxResults(1);
		return (User) criteria.uniqueResult();
	}

}
